#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: crud.py
# @time: 2021/4/13 15:43
# @desc:
from datetime import datetime
from typing import List, Dict

from application.standard_part.queryModels import Args
from views.configs import JSON_OSS_ADDRESS


def update_standard_part_show(json_data, args: List[Args]):
    """
    更新标准零件的尺寸，用来显示，实际上并没有更新到数据库里。

    :param json_data:
    :param args:
    :return:
    """
    for i in args:
        if json_data["args"]["name"] == i.name:
            json_data["args"]["v"] = i.v
    return json_data


def generate_standard_part_data(
        number: str,
        file_path: str,
        category: str,
        desc: str = "",
        version: str = "1.0",
        isFeature: bool = False,
        isFlag: bool = False,
) -> Dict:
    """

    :param category:
    :param file_path: 夹具在OSS上的地址
    :param number:
    :param isFlag:
    :param isFeature:
    :param desc:
    :param version:
    """
    model = {
        "number": number,
        "time": datetime.now().strftime("%Y-%m-%d %H:%M"),
        # 存到数据库的name字段只应当包含最后一层的名字
        "name": file_path.split("/")[-1],
        "category": category,
        "desc": desc,
        "type": "4",
        "version": version,
        "isFeature": isFeature,
        "isFlag": isFlag,
        "file": {
            JSON_OSS_ADDRESS: file_path,
            "transferFormatMessage": "not transfered yet",
        },
    }

    return model
